<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>第11章：Date与Math | MarkDown的使用</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../JavaScript/JavaScript_12.html" />
    
    
    <link rel="prev" href="../JavaScript/JavaScript_10.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.11"
        data-chapter-title="第11章：Date与Math"
        data-filepath="JavaScript/JavaScript_11.md"
        data-basepath=".."
        data-revision="Sat Nov 10 2018 16:39:50 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="HTML/html_int.html">
            
                
                    <a href="../HTML/html_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML5简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="HTML/gitbook_use.html">
            
                
                    <a href="../HTML/gitbook_use.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        第0章：gitbook的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="HTML/lesson1.html">
            
                
                    <a href="../HTML/lesson1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        第1章：常用标签
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="HTML/lesson2.html">
            
                
                    <a href="../HTML/lesson2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第2章：列表与图片
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="HTML/lesson3.html">
            
                
                    <a href="../HTML/lesson3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        第3章：表格与表单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="HTML/lesson4.html">
            
                
                    <a href="../HTML/lesson4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        第4章：实体字符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="HTML/lesson5.html">
            
                
                    <a href="../HTML/lesson5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        第5章：多媒体和iframe
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="CSS/css_int.html">
            
                
                    <a href="../CSS/css_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        CSS简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="CSS/css_1.html">
            
                
                    <a href="../CSS/css_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        第1章：引入css
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="CSS/css_2.html">
            
                
                    <a href="../CSS/css_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        第2章：选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="CSS/css_3.html">
            
                
                    <a href="../CSS/css_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        第3章：属性选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="CSS/css_4.html">
            
                
                    <a href="../CSS/css_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        第4章：伪类选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="CSS/css_5.html">
            
                
                    <a href="../CSS/css_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        第5章：盒子模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="CSS/css_6.html">
            
                
                    <a href="../CSS/css_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        第6章：伪对象选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="CSS/css_7.html">
            
                
                    <a href="../CSS/css_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        第7章：font字体与边框
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="CSS/css_8.html">
            
                
                    <a href="../CSS/css_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        第8章：行高
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="CSS/css_9.html">
            
                
                    <a href="../CSS/css_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        第9章：文字与背景
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="CSS/css_10.html">
            
                
                    <a href="../CSS/css_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        第10章：浮动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="CSS/css_11.html">
            
                
                    <a href="../CSS/css_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        第11章：定位与渐变
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="CSS/css_12.html">
            
                
                    <a href="../CSS/css_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.12.</b>
                        
                        第12章：css过渡与变形
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="CSS/css_13.html">
            
                
                    <a href="../CSS/css_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.13.</b>
                        
                        第13章：css动画
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="CSS/css_14.html">
            
                
                    <a href="../CSS/css_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.14.</b>
                        
                        第14章：css滤镜
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="CSS/css_15.html">
            
                
                    <a href="../CSS/css_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.15.</b>
                        
                        第15章：swiper与地图插件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="CSS/css_16.html">
            
                
                    <a href="../CSS/css_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.16.</b>
                        
                        第16章：移动端rem布局
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="CSS/css_17.html">
            
                
                    <a href="../CSS/css_17.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.17.</b>
                        
                        第17章：伸缩盒子
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="SASS/sass_int.html">
            
                
                    <a href="../SASS/sass_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        sass简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="SASS/sass_1.html">
            
                
                    <a href="../SASS/sass_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        第1章：sass安装与使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="SASS/sass_2.html">
            
                
                    <a href="../SASS/sass_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        第2章：sass语法入门
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="Bootstrap/Bootstrap_int.html">
            
                
                    <a href="../Bootstrap/Bootstrap_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Bootstrap简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="Bootstrap/Bootstrap_1.html">
            
                
                    <a href="../Bootstrap/Bootstrap_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        第1章：Bootstrap
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="JavaScript/JavaScript_int.html">
            
                
                    <a href="../JavaScript/JavaScript_int.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        JavaScript简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="JavaScript/JavaScript_1.html">
            
                
                    <a href="../JavaScript/JavaScript_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        第1章：JavaScript
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="JavaScript/JavaScript_2.html">
            
                
                    <a href="../JavaScript/JavaScript_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        第2章：变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="JavaScript/JavaScript_3.html">
            
                
                    <a href="../JavaScript/JavaScript_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        第3章：Number
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="JavaScript/JavaScript_4.html">
            
                
                    <a href="../JavaScript/JavaScript_4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        第4章：数据类型判断
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="JavaScript/JavaScript_5.html">
            
                
                    <a href="../JavaScript/JavaScript_5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        第5章：运算符与字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="JavaScript/JavaScript_6.html">
            
                
                    <a href="../JavaScript/JavaScript_6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        第6章：循环与流程控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="JavaScript/JavaScript_7.html">
            
                
                    <a href="../JavaScript/JavaScript_7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        第7章：函数与作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="JavaScript/JavaScript_8.html">
            
                
                    <a href="../JavaScript/JavaScript_8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.8.</b>
                        
                        第8章：String方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.9" data-path="JavaScript/JavaScript_9.html">
            
                
                    <a href="../JavaScript/JavaScript_9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.9.</b>
                        
                        第9章：数组方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.10" data-path="JavaScript/JavaScript_10.html">
            
                
                    <a href="../JavaScript/JavaScript_10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.10.</b>
                        
                        第10章：定时器与排序
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.11" data-path="JavaScript/JavaScript_11.html">
            
                
                    <a href="../JavaScript/JavaScript_11.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.11.</b>
                        
                        第11章：Date与Math
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.12" data-path="JavaScript/JavaScript_12.html">
            
                
                    <a href="../JavaScript/JavaScript_12.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.12.</b>
                        
                        第12章：简单的DOM操作与垃圾回收
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.13" data-path="JavaScript/JavaScript_13.html">
            
                
                    <a href="../JavaScript/JavaScript_13.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.13.</b>
                        
                        第13章：DOM操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.14" data-path="JavaScript/JavaScript_14.html">
            
                
                    <a href="../JavaScript/JavaScript_14.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.14.</b>
                        
                        第14章：DOM修改样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.15" data-path="JavaScript/JavaScript_15.html">
            
                
                    <a href="../JavaScript/JavaScript_15.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.15.</b>
                        
                        第15章：DOM常用标签属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.16" data-path="JavaScript/JavaScript_16.html">
            
                
                    <a href="../JavaScript/JavaScript_16.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.16.</b>
                        
                        第16章：鼠标坐标与拖拽
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >MarkDown的使用</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="date&#x4E0E;math">Date&#x4E0E;Math</h1>
<h3 id="1date">1.Date</h3>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;&#x540D;</th>
<th style="text-align:center">&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>new Date(string)</td>
<td style="text-align:center">string&#x9ED8;&#x8BA4;&#x4E0D;&#x586B;&#x8868;&#x793A;&#x5F53;&#x524D;&#x65F6;&#x95F4;; string &#x53EF;&#x4EE5;&#x5199;&#x6210; &quot;2018.11.11 0:0:0&quot;    (&#x5F53;&#x524D;&#x65F6;&#x533A;); string &#x4E3A;null &#x6807;&#x51C6;&#x65F6;&#x95F4;&#x7684;1970&#x5E74;1&#x6708;1&#x65E5; 0:0:0</td>
</tr>
<tr>
<td>getFullYear()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x5E74;&#x4EFD;</td>
</tr>
<tr>
<td>getMonth()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x6708;&#x4EFD;&#xFF0C;&#x4ECE;0&#x5F00;&#x59CB;&#x6570;&#xFF0C;&#x8BB0;&#x5F97;&#x6708;&#x4EFD;+1</td>
</tr>
<tr>
<td>getDate()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x65E5;</td>
</tr>
<tr>
<td>getDay()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x65E5;&#x5386;&#x661F;&#x671F;&#x51E0;&#xFF0C;&#x4ECE;&#x5468;&#x65E5;(0)&#x5F00;&#x59CB;</td>
</tr>
<tr>
<td>getHours()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x65F6;</td>
</tr>
<tr>
<td>getMinutes()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x5206;</td>
</tr>
<tr>
<td>getSeconds()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x79D2;</td>
</tr>
<tr>
<td>getMilliseconds()</td>
<td style="text-align:center">&#x83B7;&#x53D6;&#x6BEB;&#x79D2;</td>
</tr>
</tbody>
</table>
<pre><code>    /**    new Date(string)
     *         string &#x9ED8;&#x8BA4;&#x4E0D;&#x586B;&#x8868;&#x793A;&#x5F53;&#x524D;&#x65F6;&#x95F4;
     *         string &#x53EF;&#x4EE5;&#x5199;&#x6210; &quot;2018.11.11 0:0:0&quot;    (&#x5F53;&#x524D;&#x65F6;&#x533A;)
     *         string &#x4E3A;null &#x6807;&#x51C6;&#x65F6;&#x95F4;&#x7684;1970&#x5E74;1&#x6708;1&#x65E5; 0:0:0
     * */                         
    var d = new Date(&quot;2018.11.11 8:10:20&quot;);
    console.log(d)

    // &#x65F6;&#x95F4;&#x6233;         &#x8BA1;&#x7B97;&#x4ECE;1970&#x5E74;&#x5230;&#x73B0;&#x5728;d&#x7684;&#x6BEB;&#x79D2;&#x6570;
    console.log(d.getTime())    // &#x672C;&#x5730;&#x8BBE;&#x5907;&#x65F6;&#x95F4;

    // &#x6765;&#x81EA;&#x670D;&#x52A1;&#x5668;&#x7684;&#x65F6;&#x95F4;&#x6233; &#x548C; &#x672C;&#x5730;&#x7684;&#x65F6;&#x95F4;&#x6233;&#x5BF9;&#x6BD4;

    // &#x5E74;
    console.log( &quot;&#x5E74;&#x4EFD;&#xFF1A;&quot;,d.getFullYear() )
    // &#x6708;    &#x4ECE;0&#x5F00;&#x59CB;&#x6570;&#xFF0C;&#x8BB0;&#x5F97;&#x6708;&#x4EFD;+1
    console.log( &quot;&#x6708;&#x4EFD;&#xFF1A;&quot;,d.getMonth() )
    // &#x65E5;&#x671F;
    console.log( &quot;&#x65E5;&#x671F;&#xFF1A;&quot;,d.getDate() )
    // &#x65E5;&#x5386;&#x661F;&#x671F;&#x51E0;    &#x4ECE;&#x5468;&#x65E5;(0)&#x5F00;&#x59CB;
    console.log( &quot;&#x661F;&#x671F;&#xFF1A;&quot;,d.getDay() )

    console.log( &quot;&#x65F6;&#xFF1A;&quot;,d.getHours() )
    console.log( &quot;&#x5206;&#xFF1A;&quot;,d.getMinutes() )
    console.log( &quot;&#x79D2;&#xFF1A;&quot;,d.getSeconds() )
    console.log( &quot;&#x6BEB;&#x79D2;&#xFF1A;&quot;,d.getMilliseconds() )
</code></pre><pre><code>    // &#x7EC3;&#x4E60;&#xFF1A;&#x53CC;&#x5341;&#x4E00;&#x5012;&#x8BA1;&#x65F6;(&#x65F6;&#xFF1A;&#x5206;&#xFF1A;&#x79D2;)

    var t1 = setInterval(function(){
        var day11 = new Date(&quot;2018.11.11 0:0:0&quot;);
        var today = new Date();
        var time = day11 - today;    // &#x53CC;&#x5341;&#x4E00;&#x79BB;&#x73B0;&#x5728;&#x65F6;&#x95F4;&#x7684;&#x65F6;&#x95F4;&#x5DEE;
        // &#x5929;
        var Day = (time / 3600000) / 24;
        Day = Math.floor(Day);
        if(Day&lt;10){
            Day = &quot;0&quot; + Day;
        }
        // &#x5C0F;&#x65F6;
        var Hours = time % (60 * 60 * 1000 * 24) / (60 * 60 * 1000);
        Hours = Math.floor(Hours);
        if(Hours&lt;10){
            Hours = &quot;0&quot; + Hours;
        }
        // &#x5206;&#x949F;
        var Minutes = time % (60 * 60 * 1000) / (60 * 1000);
        Minutes = Math.floor(Minutes);
        if(Minutes&lt;10){
            Minutes = &quot;0&quot; + Minutes;
        }
        // &#x79D2;
        var Seconds = time % (60 * 1000) / 1000;
        Seconds = Math.floor(Seconds);
        if(Seconds&lt;10){
            Seconds = &quot;0&quot; + Seconds;
        }

        console.log(&quot;&#x5012;&#x8BA1;&#x65F6;:&quot;,Day,&quot;&#x5929;&quot;,Hours,&quot;&#x65F6;&quot;,Minutes,&quot;&#x5206;&quot;,Seconds,&quot;&#x79D2;&quot;)
    },1000)
</code></pre><h3 id="2math">2.Math</h3>
<table>
<thead>
<tr>
<th>&#x65B9;&#x6CD5;&#x540D;</th>
<th style="text-align:center">&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>Math.PI</td>
<td style="text-align:center">&#x5706;&#x5468;&#x7387;</td>
</tr>
<tr>
<td>Math.SQRTa</td>
<td style="text-align:center">&#x6839;&#x53F7;a</td>
</tr>
<tr>
<td>Math.SQRTa_b</td>
<td style="text-align:center">&#x6839;&#x53F7;a/b</td>
</tr>
<tr>
<td>Math.pow(a,b)</td>
<td style="text-align:center">a&#x7684;b&#x6B21;&#x65B9;</td>
</tr>
<tr>
<td>Math.sqrt(a)</td>
<td style="text-align:center">&#x5E73;&#x65B9;&#x6839;</td>
</tr>
<tr>
<td>Math.cbrt(a)</td>
<td style="text-align:center">&#x7ACB;&#x65B9;&#x6839;</td>
</tr>
<tr>
<td>Math.hypot(a,b)</td>
<td style="text-align:center">(a&#x5E73;&#x65B9; + b&#x5E73;&#x65B9;)&#x7684;&#x548C;&#xFF0C;&#x5F00;&#x6839;&#x53F7;&#xFF0C;&#x53EF;&#x63A5;&#x6536;&#x591A;&#x4E2A;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td>Math.random()</td>
<td style="text-align:center">&#x968F;&#x673A;&#x6570;</td>
</tr>
<tr>
<td>Math.ceil(a)</td>
<td style="text-align:center">&#x5411;&#x4E0A;&#x53D6;&#x6574;</td>
</tr>
<tr>
<td>Math.floor(a)</td>
<td style="text-align:center">&#x5411;&#x4E0B;&#x53D6;&#x6574;</td>
</tr>
<tr>
<td>Math.round(a)</td>
<td style="text-align:center">&#x56DB;&#x820D;&#x4E94;&#x5165;</td>
</tr>
<tr>
<td>Math.max(a,b,c...)</td>
<td style="text-align:center">&#x53D6;&#x6700;&#x5927;&#x503C;</td>
</tr>
<tr>
<td>Math.min(a,b,c...)</td>
<td style="text-align:center">&#x53D6;&#x6700;&#x5C0F;&#x503C;</td>
</tr>
<tr>
<td>Math.max.apply(null,[a,b,c...])</td>
<td style="text-align:center">&#x53D6;&#x6570;&#x7EC4;&#x5185;&#x7684;&#x6700;&#x5927;&#x503C;</td>
</tr>
<tr>
<td>Math.sin(Math.PI)</td>
<td style="text-align:center">&#x6B63;&#x5F26;</td>
</tr>
<tr>
<td>Math.cos(Math.PI)</td>
<td style="text-align:center">&#x4F59;&#x5F26;</td>
</tr>
<tr>
<td>Math.tan(Math.PI/4)</td>
<td style="text-align:center">&#x6B63;&#x5207;</td>
</tr>
<tr>
<td>Math.abs(-a)</td>
<td style="text-align:center">&#x7EDD;&#x5BF9;&#x503C;</td>
</tr>
</tbody>
</table>
<pre><code>    // Math&#x5185;&#x7F6E;&#x5BF9;&#x8C61;    Math.random()

    // &#x5706;&#x5468;&#x7387;
    console.log(&quot;&#x5706;&#x5468;&#x7387;&quot;,Math.PI)
    // &#x6839;&#x53F7;2
    console.log(&quot;&#x6839;&#x53F7;2&quot;,Math.SQRT2)
    // &#x6839;&#x53F7;1/2
    console.log(&quot;&#x6839;&#x53F7;1/2&quot;,Math.SQRT1_2)

    // pow() 
    var num = 2;
    console.log(&quot;2&#x7684;3&#x6B21;&#x65B9;&quot;,Math.pow(num,3))
    console.log(&quot;&#x5E73;&#x65B9;&#x6839;&quot;,Math.sqrt(4))
    console.log(&quot;&#x7ACB;&#x65B9;&#x6839;&quot;,Math.cbrt(27))

    // a&#x5E73;&#x65B9; + b&#x5E73;&#x65B9; == c&#x5E73;&#x65B9;
    // Math.hypot(3,4) --&gt; a&#x5E73;&#x65B9; + b&#x5E73;&#x65B9;     &#x7684;&#x548C;&#xFF0C;&#x5F00;&#x6839;&#x53F7;&#xFF0C;&#x53EF;&#x63A5;&#x6536;&#x591A;&#x4E2A;&#x51FD;&#x6570;
    console.log(Math.hypot(3,4) == 5)

    console.log(&quot;&#x968F;&#x673A;&#x6570;&quot;,Math.random())                    // &#x968F;&#x673A;&#x6570; 0-1
    console.log(&quot;&#x5411;&#x4E0A;&#x53D6;&#x6574;&quot;,Math.ceil(5.9999))            // &#x5411;&#x4E0A;&#x53D6;&#x6574;    6
    console.log(&quot;&#x5411;&#x4E0B;&#x53D6;&#x6574;&quot;,Math.floor(5.9999))            // &#x5411;&#x4E0B;&#x53D6;&#x6574;    5
    console.log(&quot;&#x56DB;&#x820D;&#x4E94;&#x5165;&quot;,Math.round(5.5))                // &#x56DB;&#x820D;&#x4E94;&#x5165;    6


    // &#x53D6;&#x6700;&#x5927;&#x503C;
    console.log(&quot;&#x53D6;&#x6700;&#x5927;&#x503C;&quot;,Math.max(15,6,4,50))            // &#x53D6;&#x6700;&#x5927;&#x503C;
    console.log(&quot;&#x53D6;&#x6700;&#x5C0F;&#x503C;&quot;,Math.min(15,6,4,50))            // &#x53D6;&#x6700;&#x5C0F;&#x503C;

    console.log(Math.max([1,2,3]))                        // ???
    // toString.call()        &#x6539;&#x53D8;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x6307;&#x5411;
    console.log(Math.max.apply(null,[1,2,3,4]))            // Math.max([1,2,3,4])



    console.log(&quot;&#x6B63;&#x5F26;&quot;,Math.sin(Math.PI))
    console.log(&quot;&#x4F59;&#x5F26;&quot;,Math.cos(Math.PI))
    console.log(&quot;&#x6B63;&#x5207;&quot;,Math.tan(Math.PI/4))

    console.log(&quot;&#x7EDD;&#x5BF9;&#x503C;&quot;,Math.abs(-2))
</code></pre><pre><code>    // &#x7EC3;&#x4E60;&#xFF1A;[5,16)
    /*var num = Math.random()*11 + 5;
    num = Math.floor(num);
    console.log(num)*/

    function myRandom( min , max){
        var rang = max - min;
        var rand = (Math.random() * rang) + min;
        rand = Math.floor(rand);
        return rand;
    }
    console.log(myRandom(5,16))



    // &#x8BF7;&#x5206;&#x6790;console.log(1 +- +- + + + + + 1) &#x7684;&#x7ED3;&#x679C;&#x4E3A;&#x4EC0;&#x4E48;&#x7B49;&#x4E8E;2
    console.log(1 + - + - + + + + + + 1)
    console.log( - &quot;-1&quot;)          // &#x9690;&#x6027;&#x8F6C;&#x6362;
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../JavaScript/JavaScript_10.html" class="navigation navigation-prev " aria-label="Previous page: 第10章：定时器与排序"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../JavaScript/JavaScript_12.html" class="navigation navigation-next " aria-label="Next page: 第12章：简单的DOM操作与垃圾回收"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
